﻿Imports BUS
Imports DTO

Public Class UserControlTraCuuPhieuRut
    Private prtCrt As New PhieuRutTienCrt()
    Private Sub CapNhatTieuChuanTraCuu(ByVal bUpdated As Boolean)
        If (bUpdated) Then
            If (txtMaSo.Text <> "") Then
                prtCrt.MaSo = Integer.Parse(txtMaSo.Text)
            Else
                prtCrt.MaSo = 0
            End If
            prtCrt.TenKH = txtTenKH.Text
            If (chkSoTienRut.Checked) Then
                prtCrt.SoTienRutTu = Double.Parse(txtSoTienRutTu.Text)
                prtCrt.SoTienRutDen = Double.Parse(txtSoTienRutDen.Text)
            Else
                prtCrt.SoTienRutTu = 0.0
                prtCrt.SoTienRutDen = 0.0
            End If
            If chkNgayRut.Checked Then
                prtCrt.NgayRutTu = dtpNgayRutTu.Value
                prtCrt.NgayRutDen = dtpNgayRutDen.Value
            End If
            prtCrt.ChkTenKH = chkKhachHang.Checked
            prtCrt.ChkSoTienRut = chkSoTienRut.Checked
            prtCrt.ChkNgayRut = chkNgayRut.Checked
        End If
    End Sub

 






    Private Sub chkNgayRut_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNgayRut.CheckedChanged
        If chkNgayRut.Checked Then
            dtpNgayRutTu.Enabled = True
            dtpNgayRutDen.Enabled = True
        Else
            dtpNgayRutTu.Enabled = False
            dtpNgayRutDen.Enabled = False
        End If
    End Sub

    Private Sub chkSoTienRut_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSoTienRut.CheckedChanged
        If chkSoTienRut.Checked Then
            txtSoTienRutTu.Enabled = True
            txtSoTienRutDen.Enabled = True
        Else
            txtSoTienRutTu.Enabled = False
            txtSoTienRutDen.Enabled = False
        End If
    End Sub

    Private Sub chkKhachHang_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkKhachHang.CheckedChanged
        If chkKhachHang.Checked Then
            txtTenKH.Enabled = True
        Else
            txtTenKH.Enabled = False
        End If
    End Sub

    Private Sub btnTraCuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTraCuu.Click
        Dim maso As Integer
        If txtMaSo.Text.Length > 0 And (Integer.TryParse(txtMaSo.Text, maso) = False Or maso <= 0) Then
            MessageBox.Show("Mã sổ không hợp lệ!")
            txtMaSo.Focus()
            Return
        End If
        Dim temp As Double
        Dim temp1 As Double
        If chkSoTienRut.Checked = True And (Double.TryParse(txtSoTienRutTu.Text, temp) = False Or temp < 0) Then
            MessageBox.Show("Số tiền rút từ không hợp lệ!")
            txtSoTienRutTu.Focus()
            Return
        End If
        If chkSoTienRut.Checked = True And (Double.TryParse(txtSoTienRutDen.Text, temp1) = False Or temp1 < 0) Then
            MessageBox.Show("Số tiền rút đến không hợp lệ!")
            txtSoTienRutDen.Focus()
            Return
        End If
        If temp > temp1 Then
            MessageBox.Show("Số tiền rút từ lớn hơn tiền rút đến, không hợp lệ!")
            txtSoTienRutTu.Focus()
            Return
        End If
        Dim dsprt As New List(Of PhieuRutTienCrt)()
        Try
            CapNhatTieuChuanTraCuu(True)
            Dim prtBUS As New PhieuRutTienBUS()
            dsprt = prtBUS.TimKiemTheoNhieuTieuChi(prtCrt)
            If dsprt.Count <= 0 Then
                MessageBox.Show("Không tìm thấy dữ liệu")
                Return
            End If
            Dim frmDS As New frmDanhSachTraCuuPhieuRutTien()
            frmDS.DSPGT = dsprt
            frmDS.ShowDialog()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
      
    End Sub

    Private Sub UserControlTraCuuPhieuRut_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class
